package org.beetl.sql.gen.simple.controller;

import org.beetl.core.Template;
import org.beetl.sql.clazz.kit.StringKit;
import org.beetl.sql.gen.BaseProject;
import org.beetl.sql.gen.Entity;
import org.beetl.sql.gen.SourceConfig;
import org.beetl.sql.gen.simple.BaseTemplateSourceBuilder;

import java.io.Writer;
import java.util.Arrays;

/**
 * 表对应实体的AddVo代码，参考AddVo.btl
 */
public class VoBuilder extends BaseTemplateSourceBuilder {

	public VoBuilder(String tableName) {
		super("controller."+tableName+".vo");
	}

	//Override
	@Override
	public void generate(BaseProject project, SourceConfig config, Entity entity) {


		Template template = groupTemplate.getTemplate("beetlsqlTemplates/controller/vo/AddVo.btl");
		template.binding("package", project.getBasePackage(this.name));
		template.binding("attrs", entity.getList());
		Writer writer = project.getWriterByName(this.name,"AddVo.java");
		template.renderTo(writer);

		Template template2 = groupTemplate.getTemplate("beetlsqlTemplates/controller/vo/DeleteVo.btl");
		template2.binding("package", project.getBasePackage(this.name));
		template2.binding("attrs", entity.getList());
		Writer writer2 = project.getWriterByName(this.name,"DeleteVo.java");
		template2.renderTo(writer2);

		Template template3 = groupTemplate.getTemplate("beetlsqlTemplates/controller/vo/GetInfoByParamVo.btl");
		template3.binding("package", project.getBasePackage(this.name));
		template3.binding("attrs", entity.getList());
		Writer writer3 = project.getWriterByName(this.name,"GetInfoByParamVo.java");
		template3.renderTo(writer3);

		Template template4 = groupTemplate.getTemplate("beetlsqlTemplates/controller/vo/GetInfoListByParamVo.btl");
		template4.binding("package", project.getBasePackage(this.name));
		template4.binding("attrs", entity.getList());
		Writer writer4 = project.getWriterByName(this.name,"GetInfoListByParamVo.java");
		template4.renderTo(writer4);

		Template template5 = groupTemplate.getTemplate("beetlsqlTemplates/controller/vo/GetPageInfoVo.btl");
		template5.binding("package", project.getBasePackage(this.name));
		template5.binding("attrs", entity.getList());
		Writer writer5 = project.getWriterByName(this.name,"GetPageInfoVo.java");
		template5.renderTo(writer5);

		Template template6 = groupTemplate.getTemplate("beetlsqlTemplates/controller/vo/UpdateVo.btl");
		template6.binding("package", project.getBasePackage(this.name));
		template6.binding("attrs", entity.getList());
		Writer writer6 = project.getWriterByName(this.name,"UpdateVo.java");
		template6.renderTo(writer6);


	}
}
